package com.kkang.betmachine.util;

import com.kkang.betmachine.config.MatheType;
import com.kkang.betmachine.ryc.RycMatcheUitl;

import java.util.List;

/**
 * @author yongk_liu
 **/
public class MatcheFactory {

    private static RycMatcheUitl rycMatcheUitl;

    private MatheType matheType;

    private MatcheFactory() {
    }

    private MatcheFactory(MatheType matheType) {
        this.matheType = matheType;
    }

    /**
     * 初始化工厂，直接从网络获取
     *
     * @return
     */
    public static MatcheFactory initFactory(MatheType matheType) {
        rycMatcheUitl = initUtil(matheType.getClassName());
        return new MatcheFactory(matheType);
    }

    private static RycMatcheUitl initUtil(String className) {
        try {
            Class<?> aClass = Class.forName(className);
            return (RycMatcheUitl) aClass.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 连接如意彩 获取比赛信息
     *
     * @return
     */
    public List getMaches() {
        return rycMatcheUitl.pullMatches(matheType);
    }

}
